﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace KFC.Utils
{
    public class XML_parse
    {
        private string _filePath;
        private XmlDocument xDoc;
        private int numberElement = 0;

        public int NumberElement
        {
            get { return numberElement; }
            set { numberElement = value; }
        }
        public XML_parse(string filePath)
        {
            _filePath = filePath;
            xDoc = new XmlDocument();
            xDoc.Load(_filePath);

        }
        public List<Element> GetAllElement(string root)
        {
            List<Element> list = new List<Element>();
            XmlNodeList nodeList = xDoc.SelectNodes(root);
            foreach (XmlNode n in nodeList)
            {
                numberElement = 0;
                foreach (XmlNode child in n.ChildNodes)
                {
                    Element el = new Element(child.Name, child.InnerText);
                    list.Add(el);
                    numberElement++;
                }
            }
            return list;
        }


    }
}
